#include "path_utils.hpp"
#include "world.hpp"

namespace hex {

void get_reachable_tiles(const world& w, const location& src, int max_cost,
                         std::map<location, int>& res,
						 int current_cost)
{
	std::map<location, int>::iterator itor = res.find(src);
	if(itor != res.end()) {
		if(itor->second <= current_cost) {
			return;
		}

		itor->second = current_cost;
	} else {
		res[src] = current_cost;
	}

	location adj[6];
	get_adjacent_tiles(src, adj);
	for(int n = 0; n != 6; ++n) {
		const int cost = w.move_cost(src, static_cast<DIRECTION>(n));
		if(cost < 0 || cost + current_cost > max_cost) {
			continue;
		}

		get_reachable_tiles(w, adj[n], max_cost, res, current_cost + cost);
	}
}

}
